<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <el-date-picker v-model="listQuery.revStart" type="date"  format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="领取开始时间"></el-date-picker>
    <el-date-picker v-model="listQuery.revEnd" type="date" :picker-options="pickerSelectBeginDateAfter"  format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="领取结束时间"></el-date-picker>
    <el-select class="filter-item" v-model="listQuery.couType" placeholder="红包类型">
          <el-option label="普通红包" value="0"> </el-option>
          <el-option label="随机红包" value="1"> </el-option>
    </el-select>
    <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">查询</el-button>
    <el-button class="filter-item"  v-if="couponManager_btn_add"  style="margin-left: 10px;" @click="handleCreateNormal" type="primary" icon="plus">普通红包</el-button>
    <el-button class="filter-item"  v-if="couponManager_btn_add"  style="margin-left: 10px;" @click="handleCreateRandom" type="primary" icon="plus">随机红包</el-button>
  </div>
  <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">
    <el-table-column align="center" label="编号" width="160px;"> <template scope="scope">
          <span>{{scope.row.couId}}</span>
    </template> </el-table-column>
    <el-table-column width="150px" align="center" label="红包名称"> <template scope="scope">
          <span>{{scope.row.couName}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="红包类型"> <template scope="scope">
          <span v-if="scope.row.couType == '0'">普通红包</span>
          <span v-else>随机红包</span>
    </template> </el-table-column>
    <el-table-column width="120px" align="center" label="红包总金额"> <template scope="scope">
          <span>{{scope.row.couSum}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="使用红包最低金额"> <template scope="scope">
          <span>{{scope.row.totalPay}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="红包抵扣金额"> <template scope="scope">
          <span>{{scope.row.subtraction}}</span>
    </template> </el-table-column>
    <el-table-column width="200px" align="center" label="触发事件"> <template scope="scope">
          <span>{{scope.row.incCode}}</span>
    </template> </el-table-column>
    <el-table-column width="180px" align="center" label="红包开始时间"> <template scope="scope">
          <span>{{scope.row.startTime}}</span>
    </template> </el-table-column>
    <el-table-column width="180px" align="center" label="红包到期时间"> <template scope="scope">
          <span>{{scope.row.endTime}}</span>
    </template> </el-table-column>
    <el-table-column width="110px" align="center" label="是否可领取"> <template scope="scope">
          <span v-if="scope.row.couStatus == '00'">可领取</span>
          <span v-else>不可领取</span>
    </template> </el-table-column>
    <el-table-column width="180px" align="center" label="领取开始时间"> <template scope="scope">
          <span>{{scope.row.revStart}}</span>
    </template> </el-table-column>
    <el-table-column width="180px" align="center" label="领取结束时间"> <template scope="scope">
          <span>{{scope.row.revEnd}}</span>
    </template> </el-table-column>
    <el-table-column width="200px" align="center" label="使用场景"> <template scope="scope">
          <span>{{scope.row.sceneId}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="红包数量"> <template scope="scope">
          <span>{{scope.row.couAmt}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="领取方式"> <template scope="scope">
          <span v-if="scope.row.payment == '02'">手动领取</span>
          <span v-else>自动领取</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="每天限领次数"> <template scope="scope">
          <span>{{scope.row.everyDay}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="每周限领次数"> <template scope="scope">
          <span>{{scope.row.everyWeek}}</span>
    </template> </el-table-column>
    <el-table-column width="100px" align="center" label="每月限领次数"> <template scope="scope">
          <span>{{scope.row.everyMonth}}</span>
    </template> </el-table-column>
    <el-table-column align="center" label="操作" width="300px"> <template scope="scope">
        <el-button v-if="couponManager_btn_info" size="small" type="success" @click="handleGetInfo(scope.row)">查看</el-button>
        <el-button v-if="scope.row.couStatus == '01' && scope.row.isOpen == '00' && scope.row.couType == 0 && couponManager_btn_info" size="small" type="success" @click="handleUpdate(scope.row)">修改</el-button>
        <el-button v-if="scope.row.couStatus == '00' && couponManager_btn_close" size="small" type="danger" @click="handleClose(scope.row)">停用</el-button>
    </template> </el-table-column>
  </el-table>
  <div v-show="!listLoading" class="pagination-container">
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
  </div>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
    <el-form :model="form" :rules="rules" ref="form" label-width="150px">
      <el-form-item label="红包名称" prop="couName">
        <el-input v-model="form.couName" placeholder="请输入红包名"></el-input>
      </el-form-item>
      <el-form-item label="使用红包最低金额" prop="totalPay">
        <el-input type="number" v-model="form.totalPay" placeholder="请输入使用红包最低金额" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="红包抵扣金额" prop="subtraction">
        <el-input type="number" v-model="form.subtraction" placeholder="请输入红包抵扣金额" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="红包开始时间" prop="createTime">
        <el-date-picker  v-model="form.startTime" type="date" :picker-options="pickerStartDateBegin" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="红包到期时间" prop="endTime">
        <el-date-picker v-model="form.endTime" type="date" :picker-options="pickerEndDateAfter" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="是否可领取">
        <el-select class="filter-item" v-model="form.couStatus" placeholder="请选择">
          <el-option label="可领取" value="00"> </el-option>
          <el-option label="不可领取" value="01"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="领取开始时间" prop="revStart">
        <el-date-picker v-model="form.revStart" type="date" :picker-options="pickerRevDateBegin" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="领取结束时间" prop="revEnd">
        <el-date-picker v-model="form.revEnd" type="date" :picker-options="pickerRevDateAfter" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="使用场景"  prop="sceneId">
        <el-input v-model="form.sceneId" placeholder="请选择使用场景"  v-on:click.native="handlerChooseScene"></el-input>
      </el-form-item>
      <el-form-item label="红包数量" prop="couAmt">
        <el-input type="number" v-model="form.couAmt" placeholder="请输入红包数量" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="领取方式">
        <el-select class="filter-item" v-model="form.payment" placeholder="请选择">
          <el-option label="手动领取" value="02"> </el-option>
          <el-option label="自动领取" value="01"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="每天限领次数" prop="everyDay">
        <el-input type="number" v-model="form.everyDay" placeholder="请输入每天限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="每周限领次数" prop="everyWeek">
        <el-input type="number" v-model="form.everyWeek" placeholder="请输入每周限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="每月限领次数" prop="everyMonth">
        <el-input type="number" v-model="form.everyMonth" placeholder="请输入每月限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="触发事件" prop="incCode">
        <el-input v-model="form.incCode" placeholder="请选择触发事件"  v-on:click.native="handlerChooseIncident"></el-input>
      </el-form-item>
      <el-form-item label="红包说明">
        <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" placeholder="请输入内容" v-model="form.couInfo"> </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel('form')">取 消</el-button>
      <el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>
      <el-button v-else type="primary" @click="update('form')">确 定</el-button>
    </div>
  </el-dialog>

  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormRandom">
    <el-form :model="form" :rules="rules1" ref="form" label-width="180px">
      <el-form-item label="红包名称" prop="couName">
        <el-input v-model="form.couName" placeholder="请输入红包名"></el-input>
      </el-form-item>
      <div>第一档：
        <el-row>
          <el-col :span="10">      
            <el-form-item label="最小值" prop="oneMin">
            <el-input v-model="form.oneMin" placeholder="请输入红包最小金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="最大值" prop="oneMax">
            <el-input v-model="form.oneMax" placeholder="请输入红包最大金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">      
            <el-form-item label="总金额" prop="oneAmt">
            <el-input type="number" @blur="checkOneAmtIllegal($event)" v-model="form.oneAmt" placeholder="请输入红包总金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="总数量" prop="oneCount">
            <el-input type="number" @blur="checkOneNumIllegal($event)" v-model="form.oneCount" placeholder="请输入红包总量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div>第二档：
        <el-row>
          <el-col :span="10">      
            <el-form-item label="最小值" prop="twoMin">
            <el-input v-model="form.twoMin" placeholder="请输入红包最小金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="最大值" prop="twoMax">
            <el-input v-model="form.twoMax" placeholder="请输入红包最大金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">      
            <el-form-item label="总金额" prop="twoAmt">
            <el-input type="number" @blur="checkTwoAmtIllegal($event)" v-model="form.twoAmt" placeholder="请输入红包总金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="总数量" prop="twoCount">
            <el-input type="number" @blur="checkTwoNumIllegal($event)" v-model="form.twoCount" placeholder="请输入红包总量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div>第三档：
        <el-row>
          <el-col :span="10">      
            <el-form-item label="最小值" prop="threeMin">
            <el-input v-model="form.threeMin" placeholder="请输入红包最小金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="最大值" prop="threeMax">
            <el-input v-model="form.threeMax" placeholder="请输入红包最大金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">      
            <el-form-item label="总金额" prop="threeAmt">
            <el-input type="number" @blur="checkThreeAmtIllegal($event)" v-model="form.threeAmt" placeholder="请输入红包总金额"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">      
            <el-form-item label="总数量" prop="threeCount">
            <el-input type="number" @blur="checkThreeNumIllegal($event)" v-model="form.threeCount" placeholder="请输入红包总量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-form-item label="是否可领取">
        <el-select class="filter-item" v-model="form.couStatus" placeholder="请选择">
          <el-option label="可领取" value="00"> </el-option>
          <el-option label="不可领取" value="01"> </el-option>
        </el-select>
      </el-form-item>     
      <el-form-item label="触发事件" prop="incCode">
        <el-input v-model="form.incCode" placeholder="请选择触发事件" v-on:click.native="handlerChooseIncident"></el-input>
      </el-form-item>
      <el-form-item label="领取开始时间" prop="revStart">
        <el-date-picker v-model="form.revStart" type="date" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="领取结束时间" prop="revEnd">
        <el-date-picker v-model="form.revEnd" type="date" :picker-options="pickerRevDateAfter1" format="yyyy-MM-dd" placeholder=""></el-date-picker>
      </el-form-item>
      <el-form-item label="使用场景"  prop="sceneId">
        <el-input v-model="form.sceneId" placeholder="请选择使用场景" v-on:click.native="handlerChooseScene"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel('form')">取 消</el-button>
      <el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>
      <el-button v-else type="primary" @click="update('form')">确 定</el-button>
    </div>
  </el-dialog>

  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormRandom2">
    <el-form :model="form"  ref="form" label-width="150px">
      <el-form-item label="红包名称: " prop="couName">
        <span>{{form.couName}}</span>
      </el-form-item>
      <el-form-item label="随机红包金额: " prop="couSum">
        <span>{{form.couSum}}元</span>
      </el-form-item>
      <el-form-item label="是否可领取: ">
          <span v-if="form.couStatus == '00'">可领取</span>
          <span v-else>不可领取</span>
      </el-form-item>     
      <el-form-item label="领取开始时间: " prop="revStart">
        <span>{{form.revStart}}</span>
      </el-form-item>
      <el-form-item label="领取结束时间: " prop="revEnd">
        <span>{{form.revEnd}}</span> 
      </el-form-item>
      <el-form-item label="使用场景: "  prop="sceneId">
        <span>{{form.sceneId}}</span> 
      </el-form-item>
      <el-form-item label="红包数量: " prop="couAmt">
        <span>{{form.couAmt}}个</span> 
      </el-form-item>
      <el-form-item label="领取方式: ">
          <span v-if="form.payment == '02'">手动领取</span>
          <span v-else>自动领取</span>
      </el-form-item>
    </el-form>
  </el-dialog>

  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible2">
    <el-form :model="form"  ref="form" label-width="150px">
      <el-form-item label="红包名称" prop="couName">
        <el-input v-model="form.couName" placeholder="请输入红包名"></el-input>
      </el-form-item>
      <el-form-item label="使用红包最低金额" prop="totalPay">
        <el-input type="number" v-model="form.totalPay" placeholder="请输入使用红包最低金额" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="红包抵扣金额" prop="subtraction">
        <el-input type="number" v-model="form.subtraction" placeholder="请输入红包抵扣金额" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="红包开始时间: " prop="createTime">
        <label>{{form.startTime}}</label>
        <!-- <el-date-picker  v-model="form.startTime" type="date" :picker-options="pickerStartDateBegin" format="yyyy-MM-dd" placeholder=""></el-date-picker> -->
      </el-form-item>
      <el-form-item label="红包到期时间: " prop="endTime">
         <label>{{form.endTime}}</label>
        <!-- <el-date-picker v-model="form.endTime" type="date" :picker-options="pickerEndDateAfter" format="yyyy-MM-dd" placeholder=""></el-date-picker> -->
      </el-form-item>
      <el-form-item label="是否可领取">
        <el-select class="filter-item" v-model="form.couStatus" placeholder="请选择">
          <el-option label="可领取" value="00"> </el-option>
          <el-option label="不可领取" value="01"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="领取开始时间: " prop="revStart">
        <label>{{form.revStart}}</label>
        <!-- <el-date-picker v-model="form.revStart" type="date" :picker-options="pickerRevDateBegin" format="yyyy-MM-dd" placeholder=""></el-date-picker> -->
      </el-form-item>
      <el-form-item label="领取结束时间" prop="revEnd">
        <label>{{form.revEnd}}</label>
        <!-- <el-date-picker v-model="form.revEnd" type="date" :picker-options="pickerRevDateAfter" format="yyyy-MM-dd" placeholder=""></el-date-picker> -->
      </el-form-item>
      <el-form-item label="使用场景"  prop="sceneId">
        <el-input v-model="form.sceneId" placeholder="请选择使用场景"  v-on:click.native="handlerChooseScene"></el-input>
      </el-form-item>
      <el-form-item label="红包数量" prop="couAmt">
        <el-input type="number" v-model="form.couAmt" placeholder="请输入红包数量" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="领取方式">
        <el-select class="filter-item" v-model="form.payment" placeholder="请选择">
          <el-option label="手动领取" value="02"> </el-option>
          <el-option label="自动领取" value="01"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="每天限领次数" prop="everyDay">
        <el-input type="number" v-model="form.everyDay" placeholder="请输入每天限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="每周限领次数" prop="everyWeek">
        <el-input type="number" v-model="form.everyWeek" placeholder="请输入每周限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="每月限领次数" prop="everyMonth">
        <el-input type="number" v-model="form.everyMonth" placeholder="请输入每月限领次数" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"></el-input>
      </el-form-item>
      <el-form-item label="触发事件" prop="incCode">
        <el-input v-model="form.incCode" placeholder="请选择触发事件" v-on:click.native="handlerChooseIncident"></el-input>
      </el-form-item>
      <el-form-item label="红包说明">
        <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" placeholder="请输入内容" v-model="form.couInfo"> </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel('form')">取 消</el-button>
      <el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>
      <el-button v-else type="primary" @click="update('form')">确 定</el-button>
    </div>
  </el-dialog>
  <!-- 场景列表 -->
  <el-dialog :title="textMap[dialogStatus1]" :visible.sync="dialogSceneVisible">
    <div v-for="sce in sceneList" v-bind:key="sce.sceneCode">
      <input type="checkbox" id="scene" :value=sce.sceneCode v-model="checkedScenes" v-bind:key="sce.sceneName">
      <label for="scene">{{sce.sceneName}}</label>
    </div>
    <br>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelScene('dialogSceneVisible')">取 消</el-button>
      <el-button type="primary" @click="selectedScene('dialogSceneVisible')">确 定</el-button>
    </div>
  </el-dialog>
  <!-- 事件列表 -->
  <el-dialog :title="textMap[dialogStatus1]" :visible.sync="dialogIncVisible">
    <div v-for="inc in incidentList" v-bind:key="inc.incCode">
    <input type="checkbox" id="incident" :value=inc.incCode v-model="checkedIncidents" v-bind:key="inc.incName">
    <label for="incident">{{inc.incName}}</label>
    </div>
    <br>
    <!-- <span>选择的事件: {{ checkedIncidents }}</span> -->

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelIncident('dialogIncVisible')">取 消</el-button>
      <el-button type="primary" @click="selectIncident('dialogIncVisible')">确 定</el-button>
    </div>
  </el-dialog>
  <!-- 详情 -->
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible1">
    <el-form :model="form" ref="form" label-width="150px">
      <el-form-item label="红包名称: " prop="couName">
        <span>{{form.couName}}</span>
      </el-form-item>
      <el-form-item label="使用红包最低金额: " prop="totalPay">
        <span>{{form.totalPay}}元</span>
      </el-form-item>
      <el-form-item label="红包抵扣金额: "  prop="subtraction">
        <span>{{form.subtraction}}元</span>
      </el-form-item>
      <el-form-item label="红包开始时间: " prop="createTime">
        <span>{{form.startTime}}</span>
      </el-form-item>
      <el-form-item label="红包到期时间： " prop="endTime">
        <span>{{form.endTime}}</span>
      </el-form-item>
      <el-form-item label="是否可领取： ">
        <span v-if="form.couStatus == '00'">可领取</span>
        <span v-else>不可领取</span>
      </el-form-item>
      <el-form-item label="领取开始时间： " prop="revStart">
        <span>{{form.revStart}}</span>
      </el-form-item>
      <el-form-item label="领取结束时间： " prop="revEnd">
        <span>{{form.revEnd}}</span>
      </el-form-item>
      <el-form-item label="使用场景： " prop="sceneId">
        <span>{{form.sceneId}}</span> 
      </el-form-item>
      <el-form-item label="红包数量： " prop="couAmt">
        <span>{{form.couAmt}}个</span>
      </el-form-item>
      <el-form-item label="领取方式： ">
        <span v-if="form.payment == '01'">自动领取</span>
        <span v-else>手动领取</span>
      </el-form-item>
      <el-form-item label="每天限领次数: " prop="everyDay">
        <span>{{form.everyDay}}次</span>
      </el-form-item>
      <el-form-item label="每周限领次数: " prop="everyWeek">
        <span>{{form.everyWeek}}次</span>
      </el-form-item>
      <el-form-item label="每月限领次数: " prop="everyMonth">
        <span>{{form.everyMonth}}次</span>
      </el-form-item>
      <el-form-item label="触发事件编号: " prop="incCode">
        <span>{{form.incCode}}</span>
      </el-form-item>
      <el-form-item label="红包说明: ">
        <span>{{form.couInfo}}</span> 
      </el-form-item>
    </el-form>
  </el-dialog>
  <span class="display_name" style="display:none" id="mybox">{{token}}</span>
</div>
</template>

<script>
import {
  page,
  addObj,
  getObj,
  closeObj,
  putObj,
  getInc,
  getScene
} from '@/api/biz/operative/coupon/index'
import { mapGetters } from 'vuex'
export default {
  name: 'user',
  data() {
    return {
      form: {
        couStatus: '00',
        couInfo: '',
        couName: '',
        couId: '',
        totalPay: '',
        subtraction: '',
        startTime: '',
        endTime: '',
        revStart: '',
        revEnd: '',
        couAmt: '',
        payment: '02',
        sceneId: '',
        everyDay: '',
        everyWeek: '',
        everyMonth: '',
        incCode: '',
        actId: '',
        actToken: '',
        couType: '0',
        couSum: '',
        oneCount: '',
        oneAmt: '',
        oneMin: '',
        oneMax: '',
        twoCount: '',
        twoAmt: '',
        twoMin: '',
        twoMax: '',
        threeCount: '',
        threeAmt: '',
        threeMin: '',
        threeMax: ''
      },
      tokens: '',
      pickerBeginDateAfter1: {
        disabledDate: (time) => {
          return time.getTime() > this.form.revStart
        }
      },
      pickerEndDateAfter: {
        disabledDate: (time) => {
          return time.getTime() < this.form.startTime
        }
      },
      pickerSelectBeginDateAfter: {
        disabledDate: (time) => {
          return time.getTime() < this.listQuery.revStart
        }
      },
      pickerStartDateBegin: {
        disabledDate: (time) => {
          return time.getTime() < (Date.now() - 24 * 60 * 60 * 1000)
        }
      },
      pickerRevDateBegin: {
        disabledDate: (time) => {
          return time.getTime() > this.form.startTime
        }
      },
      pickerRevDateAfter: {
        disabledDate: (time) => {
          return time.getTime() > this.form.endTime
        }
      },
      pickerRevDateAfter1: {
        disabledDate: (time) => {
          return time.getTime() < Date.now()
        }
      },
      checkedIncidents: [],
      checkedScenes: [],
      rules1: {
        couName: [
          {
            required: true,
            message: '请输入红包名称',
            trigger: 'blur'
          },
          {
            min: 1,
            max: 20,
            message: '长度在 1 到 20 个字符',
            trigger: 'blur'
          }
        ],
        oneAmt: [
          {
            required: true,
            message: '请输入随机红包金额',
            trigger: 'blur'
          }
        ],
        oneCount: [
          {
            required: true,
            message: '请输入随机红包数量',
            trigger: 'blur'
          }
        ],
        oneMin: [
          {
            required: true,
            message: '请输入随机红包最小值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        oneMax: [
          {
            required: true,
            message: '请输入随机红包最大值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        twoAmt: [
          {
            required: true,
            message: '请输入随机红包金额',
            trigger: 'blur'
          }
        ],
        twoCount: [
          {
            required: true,
            message: '请输入随机红包数量',
            trigger: 'blur'
          }
        ],
        twoMin: [
          {
            required: true,
            message: '请输入随机红包最小值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        twoMax: [
          {
            required: true,
            message: '请输入随机红包最大值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        threeCount: [
          {
            required: true,
            message: '请输入随机红包数量',
            trigger: 'blur'
          }
        ],
        threeAmt: [
          {
            required: true,
            message: '请输入随机红包金额',
            trigger: 'blur'
          }
        ],
        threeMin: [
          {
            required: true,
            message: '请输入随机红包最小值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        threeMax: [
          {
            required: true,
            message: '请输入随机红包最大值',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ]
      },
      rules: {
        couName: [
          {
            required: true,
            message: '请输入红包名称',
            trigger: 'blur'
          },
          {
            min: 1,
            max: 20,
            message: '长度在 1 到 20 个字符',
            trigger: 'blur'
          }
        ],
        totalPay: [
          {
            required: true,
            message: '请输入使用红包最低金额',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        subtraction: [
          {
            required: true,
            message: '请输入红包抵扣金额',
            trigger: 'blur'
          },
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            message: '输入金额格式错误，请重新输入!'
          }
        ],
        couAmt: [
          {
            required: true,
            message: '请输入红包数量 (数字)',
            trigger: 'blur'

          }
        ],
        everyDay: [
          {
            required: true,
            message: '请输入每天限领次数 (数字)',
            trigger: 'blur'
          }
        ],
        everyWeek: [
          {
            required: true,
            message: '请输入每周限领次数 (数字)',
            trigger: 'blur'
          }
        ],
        everyMonth: [
          {
            required: true,
            message: '请输入每月限领次数 (数字)',
            trigger: 'blur'
          }
        ]
      },
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        actId: '',
        revStart: '',
        revEnd: '',
        couType: ''
      },
      actId: '',
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogSceneVisible: false,
      dialogFormRandom: false,
      dialogFormRandom2: false,
      dialogIncVisible: false,
      dialogStatus: '',
      dialogStatus1: '',
      couponType: '',
      couponManager_btn_edit: false,
      couponManager_btn_info: false,
      couponManager_btn_add: false,
      couponManager_btn_close: false,
      couponManager_btn_get: false,
      sceneList: null,
      incidentList: null,
      textMap: {
        update: '编辑',
        create: '新增',
        close: '关闭',
        info: '详情',
        selectScene: '选择场景',
        selectInc: '选择事件'
      },
      tableKey: 0
    }
  },
  mounted() {
    console.log('enen ' + this.$route.query.actInfo)
    this.listQuery.actId = this.$route.query.actInfo.actId
    this.actId = this.$route.query.actInfo.actId
    this.form.actId = this.$route.query.actInfo.actId
    console.log(this.actId)
    var box = document.getElementById('mybox')
    console.log(box.innerText)
    this.tokens = box.innerText
    console.log(this.tokens)
  },
  created() {
    this.getList()
    this.couponManager_btn_edit = this.elements['couponManager:btn_edit']
    this.couponManager_btn_close = this.elements['couponManager:btn_close']
    this.couponManager_btn_add = this.elements['couponManager:btn_add']
    this.couponManager_btn_info = this.elements['couponManager:btn_info']
    this.couponManager_btn_get = this.elements['couponManager:btn_get']
  },
  computed: {
    ...mapGetters([
      'elements',
      'token'
    ])
  },
  methods: {
    getList() {
      this.listLoading = true
      page(this.listQuery)
        .then(response => {
          this.list = response.data.rows
          console.log(this.list)
          this.total = response.data.total
          this.listLoading = false
        })
    },
    handleFilter() {
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleCreateNormal() {
      this.resetTemp()
      this.couponType = '0'
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
    },
    handleCreateRandom() {
      this.couponType = '1'
      this.dialogStatus = 'create'
      this.dialogFormRandom = true
    },
    checkOneNumIllegal() {
      var min = this.form.oneMin
      var max = this.form.oneMax
      var amt = this.form.oneAmt
      var count = this.form.oneCount

      if ((amt / count) < min || (amt / count) > max) {
        alert('总金额除总数量的值必须在最大值与最小值之间')
        this.form.oneCount = ''
        return
      }
    },
    checkOneAmtIllegal() {
      var min = this.form.oneMin
      var max = this.form.oneMax
      var amt = this.form.oneAmt

      if (amt < max || amt < min) {
        alert('总金额必须大于最大值')
        this.form.oneAmt = ''
        return
      }
    },
    checkTwoAmtIllegal() {
      var min = this.form.twoMin
      var max = this.form.twoMax
      var amt = this.form.twoAmt

      if (amt < max || amt < min) {
        alert('总金额必须大于最大值')
        this.form.twoAmt = ''
        return
      }
    },
    checkTwoNumIllegal() {
      var min = this.form.twoMin
      var max = this.form.twoMax
      var amt = this.form.twoAmt
      var count = this.form.twoCount
      if ((amt / count) < min || (amt / count) > max) {
        alert('总金额除总数量的值必须在最大值与最小值之间')
        this.form.twoCount = ''
        return
      }
    },
    checkThreeAmtIllegal() {
      var min = this.form.threeMin
      var max = this.form.threeMax
      var amt = this.form.threeAmt

      if (amt < max || amt < min) {
        alert('总金额必须大于最大值')
        this.form.threeAmt = ''
        return
      }
    },
    checkThreeNumIllegal() {
      var min = this.form.threeMin
      var max = this.form.threeMax
      var amt = this.form.threeAmt
      var count = this.form.threeCount
      if ((amt / count) < min || (amt / count) > max) {
        alert('总金额除总数量的值必须在最大值与最小值之间')
        this.form.threeCount = ''
        return
      }
    },
    handleUpdate(row) {
      getObj(row)
        .then(response => {
          console.log(response)
          this.dialogStatus = 'update'
          this.dialogFormVisible2 = true
          this.form = response.data
        })
    },
    handleGetInfo(row) {
      console.log('sss ' + row.couType)
      getObj(row)
        .then(response => {
          console.log(response)
          this.dialogStatus = 'info'
          if (row.couType === '1') {
            this.dialogFormRandom2 = true
          } else {
            this.dialogFormVisible1 = true
          }
          this.form = response.data
        })
    },
    handleClose(row) {
      this.$confirm('此操作将关闭红包, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          closeObj(row)
            .then(() => {
              this.$notify({
                title: '成功',
                message: '红包关闭成功',
                type: 'success',
                duration: 2000
              })
              this.getList()
            })
        })
    },
    create(formName) {
      const set = this.$refs
      set[formName].validate(valid => {
        if (valid) {
          console.log(this.tokens)
          this.form.actToken = this.tokens
          console.log(this.form.actToken)
          console.log(this.form)
          this.form.actId = this.actId
          this.form.couType = this.couponType
          this.$confirm('此操作将创建红包, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.listLoading = true
            this.dialogFormRandom = false
            this.dialogFormVisible = false
            addObj(this.form).then((response) => {
              this.listLoading = false
              console.log('sss ti=' + this.form.actId)
              console.log('==================================')
              console.log(response)
              console.log('sss ' + this.form.actId)
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 5000
              })
              this.getList()
            })
            this.form.resetTemp()
          })
        } else {
          return false
        }
      })
    },
    cancel(formName) {
      this.dialogFormVisible = false
      this.dialogFormVisible2 = false
      this.dialogFormRandom = false
      this.$refs[formName].resetFields()
    },
    update(formName) {
      const set = this.$refs
      set[formName].validate(valid => {
        if (valid) {
          this.dialogFormVisible2 = false
          putObj(this.form).then(() => {
            this.getList()
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success',
              duration: 2000
            })
          })
        } else {
          return false
        }
      })
    },
    selectedScene() {
      this.dialogSceneVisible = false
      console.log('选择的场景: ' + this.checkedScenes)
      var arr = this.checkedScenes
      this.form.sceneId = arr.join()
    },
    cancelScene(formName) {
      this.dialogSceneVisible = false
    },
    selectIncident(formName) {
      this.dialogIncVisible = false
      console.log('选择的事件: ' + this.checkedIncidents)
      var arr = this.checkedIncidents
      this.form.incCode = arr.join()
    },
    cancelIncident(formName) {
      this.dialogIncVisible = false
    },
    resetTemp() {
      this.form = {
        couStatus: '00',
        couInfo: '',
        couName: '',
        couId: '',
        totalPay: '',
        subtraction: '',
        startTime: '',
        endTime: '',
        revStart: '',
        revEnd: '',
        couAmt: '',
        payment: '02',
        sceneId: '',
        everyDay: '',
        everyWeek: '',
        everyMonth: '',
        incCode: '',
        actToken: '',
        couType: '0',
        checkedIncidents: [],
        checkedScenes: [],
        oneCount: '',
        oneAmt: '',
        oneMin: '',
        oneMax: '',
        twoCount: '',
        twoAmt: '',
        twoMin: '',
        twoMax: '',
        threeCount: '',
        threeAmt: '',
        threeMin: '',
        threeMax: ''
      }
    },
    handlerChooseScene() {
      this.dialogSceneVisible = true
      this.dialogStatus1 = 'selectScene'
      getScene()
        .then(response => {
          this.sceneList = response
        })
    },
    handlerChooseIncident() {
      this.dialogIncVisible = true
      this.dialogStatus1 = 'selectInc'
      getInc()
        .then(response => {
          this.incidentList = response
        })
    }
  }
}
</script>

<style scoped>
label {
    margin: 0px 0px !important;
}
</style>

